************************************
/*	Title: 101 analysis stage one code */
/*	Authors: Jason Rantanen & Nick Datzov */
/*	Date originally created: 11/16/2022 */
************************************

ssc install asdoc // This will install the asdoc package, which allows for nice tables to be output into Word. 

************************************
/*	Data Preparation */
************************************

import excel "Datzov & Rantanen - 101 Judge Votes 2024-11-20.xlsx", sheet("Sheet1") firstrow clear

//Manual edits

//for 15275, Hughes wrote a separate opinion not related to 101, so code his vote with the majority on 101
replace Hughes_101_vote = "2 - Invalid/Unpatentable" if uniqueID==15275
replace Hughes_majority = 1 if uniqueID==15275
replace review=. if uniqueID==15275

//for 15677, Mayer wrote a separate opinion not related to 101, so code his vote with the majority on 101
replace Mayer_101_vote = "2 - Invalid/Unpatentable" if uniqueID==15677
replace Mayer_majority = 1 if uniqueID==15677
replace review=. if uniqueID==15677

//for 15843, Newman wrote a separate opinion not related to 101, so code her vote with the majority on 101
replace Newman_101_vote = "2 - Invalid/Unpatentable" if uniqueID==15843
replace Newman_majority = 1 if uniqueID==15843
replace review=. if uniqueID==15843

//for 16015, Wallach wrote a separate opinion not related to 101, so code his vote with the majority on 101
replace Wallach_101_vote = "1 - Valid/Patentable" if uniqueID==16015
replace Wallach_majority = 1 if uniqueID==16015
replace review=. if uniqueID==16015

//for 30617, Dyk wrote a separate opinion not related to 101, so code his vote with the majority on 101
replace Dyk_101_vote = "1 - Valid/Patentable" if uniqueID==30617
replace Dyk_majority = 1 if uniqueID==30617
replace review=. if uniqueID==30617

//for 16052, Reyna agreed with the result but disagreed with some of the reasoning on 101
replace Reyna_majority = 1 if uniqueID==16052
replace review=. if uniqueID==16052

//for 16324, Plager agreed with the result but disagreed with continuing to apply 101 law
replace Plager_majority = 1 if uniqueID==16324
replace review=. if uniqueID==16324

//for 26962, Dyk agreed with the result but disagreed with application of 101 
replace Dyk_majority = 1 if uniqueID==26962
replace review=. if uniqueID==26962

tostring uniqueID_relatedDecision, replace 

/* Other Notes:
-12387: dissent says that 101 should have been sua sponte considered; majority does not consider 101; this case is before March 20, 2012, so not part of our current set. 
-27408: Vacated on procedural grounds; concurrence addresses 101 but doesn't disagree; the separate opinion is coded as "multiple" to indicate that there is such a separate opinion on 101, but it should not be counted as a dissent, even though the outcome is different from the majority because the majority is blank

replace Newman_101_vote = "2 - Invalid/Unpatentable" if uniqueID==14433; this case is before March 20, 2012, so not part of our current set.
replace Newman_majority = 1 if uniqueID==14433
replace review=. if uniqueID==14433
*/

save "2024-11-20 101 cases.dta", replace

// Data encoding - the newly-coded variables are all strings, which are more difficult to work with. We want to convert them to integers. 

sort PSM_decided // Sort the records first so that the encoding matches the prefix numbers. 
encode PSM_decided, gen(PSM_decided_n) // This replaces the entries with numbers but maintains the string text as labels. 
drop PSM_decided
rename PSM_decided_n PSM_decided

sort PSM_Multiple_Analyses // 
encode PSM_Multiple_Analyses, gen(PSM_Multiple_Analyses_n)
drop PSM_Multiple_Analyses
rename PSM_Multiple_Analyses_n PSM_Multiple_Analyses

sort PSM_ProceduralPosture // 
encode PSM_ProceduralPosture, gen(PSM_ProceduralPosture_n)
drop PSM_ProceduralPosture
rename PSM_ProceduralPosture_n PSM_ProceduralPosture

sort PSM_Outcome_OrigTrib // 
encode PSM_Outcome_OrigTrib, gen(PSM_Outcome_OrigTrib_n)
drop PSM_Outcome_OrigTrib
rename PSM_Outcome_OrigTrib_n PSM_Outcome_OrigTrib

sort PSM_Disposition_CAFC // 
encode PSM_Disposition_CAFC, gen(PSM_Disposition_CAFC_n)
drop PSM_Disposition_CAFC
rename PSM_Disposition_CAFC_n PSM_Disposition_CAFC

sort PSM_Outcome_CAFC // 
encode PSM_Outcome_CAFC, gen(PSM_Outcome_CAFC_n)
drop PSM_Outcome_CAFC
rename PSM_Outcome_CAFC_n PSM_Outcome_CAFC

sort PSM_Stage1_CAFC // 
encode PSM_Stage1_CAFC, gen(PSM_Stage1_CAFC_n)
drop PSM_Stage1_CAFC
rename PSM_Stage1_CAFC_n PSM_Stage1_CAFC

sort PSM_101_exception // 
encode PSM_101_exception, gen(PSM_101_exception_n)
drop PSM_101_exception
rename PSM_101_exception_n PSM_101_exception

sort PSM_Stage2_CAFC // 
encode PSM_Stage2_CAFC, gen(PSM_Stage2_CAFC_n)
drop PSM_Stage2_CAFC
rename PSM_Stage2_CAFC_n PSM_Stage2_CAFC

sort PSM_SecondOpinion // 
encode PSM_SecondOpinion, gen(PSM_SecondOpinion_n)
drop PSM_SecondOpinion
rename PSM_SecondOpinion_n PSM_SecondOpinion

sort PSM_ThirdOpinion // 
encode PSM_ThirdOpinion, gen(PSM_ThirdOpinion_n)
drop PSM_ThirdOpinion
rename PSM_ThirdOpinion_n PSM_ThirdOpinion


sort Bryson_101_vote  
encode Bryson_101_vote, gen(Bryson_101_vote_n)
drop Bryson_101_vote
rename Bryson_101_vote_n Bryson_101_vote

sort Chen_101_vote
encode Chen_101_vote, gen(Chen_101_vote_n)
drop Chen_101_vote
rename Chen_101_vote_n Chen_101_vote

sort Clevenger_101_vote
encode Clevenger_101_vote, gen(Clevenger_101_vote_n)
drop Clevenger_101_vote
rename Clevenger_101_vote_n Clevenger_101_vote

sort Cunningham_101_vote
encode Cunningham_101_vote, gen(Cunningham_101_vote_n)
drop Cunningham_101_vote
rename Cunningham_101_vote_n Cunningham_101_vote

sort Dyk_101_vote
encode Dyk_101_vote, gen(Dyk_101_vote_n)
drop Dyk_101_vote
rename Dyk_101_vote_n Dyk_101_vote

sort Gajarsa_101_vote
encode Gajarsa_101_vote, gen(Gajarsa_101_vote_n)
drop Gajarsa_101_vote
rename Gajarsa_101_vote_n Gajarsa_101_vote

sort Hughes_101_vote
encode Hughes_101_vote, gen(Hughes_101_vote_n)
drop Hughes_101_vote
rename Hughes_101_vote_n Hughes_101_vote

sort Linn_101_vote
encode Linn_101_vote, gen(Linn_101_vote_n)
drop Linn_101_vote
rename Linn_101_vote_n Linn_101_vote

sort Lourie_101_vote
encode Lourie_101_vote, gen(Lourie_101_vote_n)
drop Lourie_101_vote
rename Lourie_101_vote_n Lourie_101_vote

sort Mayer_101_vote
encode Mayer_101_vote, gen(Mayer_101_vote_n)
drop Mayer_101_vote
rename Mayer_101_vote_n Mayer_101_vote

sort Moore_101_vote
encode Moore_101_vote, gen(Moore_101_vote_n)
drop Moore_101_vote
rename Moore_101_vote_n Moore_101_vote

sort Newman_101_vote
encode Newman_101_vote, gen(Newman_101_vote_n)
drop Newman_101_vote
rename Newman_101_vote_n Newman_101_vote

sort OMalley_101_vote
encode OMalley_101_vote, gen(OMalley_101_vote_n)
drop OMalley_101_vote
rename OMalley_101_vote_n OMalley_101_vote

sort Prost_101_vote
encode Prost_101_vote, gen(Prost_101_vote_n)
drop Prost_101_vote
rename Prost_101_vote_n Prost_101_vote

sort Rader_101_vote
encode Rader_101_vote, gen(Rader_101_vote_n)
drop Rader_101_vote
rename Rader_101_vote_n Rader_101_vote

sort Reyna_101_vote
encode Reyna_101_vote, gen(Reyna_101_vote_n)
drop Reyna_101_vote
rename Reyna_101_vote_n Reyna_101_vote

sort Schall_101_vote
encode Schall_101_vote, gen(Schall_101_vote_n)
drop Schall_101_vote
rename Schall_101_vote_n Schall_101_vote

sort Stark_101_vote
encode Stark_101_vote, gen(Stark_101_vote_n)
drop Stark_101_vote
rename Stark_101_vote_n Stark_101_vote

sort Stoll_101_vote
encode Stoll_101_vote, gen(Stoll_101_vote_n)
drop Stoll_101_vote
rename Stoll_101_vote_n Stoll_101_vote

sort Taranto_101_vote
encode Taranto_101_vote, gen(Taranto_101_vote_n)
drop Taranto_101_vote
rename Taranto_101_vote_n Taranto_101_vote

sort Wallach_101_vote
encode Wallach_101_vote, gen(Wallach_101_vote_n)
drop Wallach_101_vote
rename Wallach_101_vote_n Wallach_101_vote

sort Plager_101_vote
encode Plager_101_vote, gen(Plager_101_vote_n)
drop Plager_101_vote
rename Plager_101_vote_n Plager_101_vote

//Limit Data to 101 decisions after Mayo was decided (3/20/12)
drop if year < 2012
drop if uniqueID==12291 // decision dated 1/20/12 
drop if uniqueID==12371 // decision dated 2/27/12
drop if uniqueID==12387 // decision dated 3/2/12

//Limit Data to 101 decisions that decided 101
drop if PSM_decided!=2

//Limit Data to non-En Banc decisions
drop if enBanc=="Yes"

save "2024-11-20 101 cases.dta", replace // This is the dataset we are working on. 

************************************
/*	Basic Statistics */
************************************

// working labels

label list PSM_decided_n PSM_Multiple_Analyses_n PSM_ProceduralPosture_n PSM_Outcome_OrigTrib_n PSM_Disposition_CAFC_n PSM_Outcome_CAFC_n PSM_Stage1_CAFC_n PSM_101_exception_n PSM_Stage2_CAFC_n PSM_SecondOpinion_n


tab PSM_decided // this shows the number of records in the dataset that the coder concluded involved a decision on PSM_101_exception

tab PSM_ProceduralPosture PSM_Outcome_OrigTrib // This is a cross-tabulation. The first variable is the vertical and the second variable is the horizontal. 

tab PSM_ProceduralPosture PSM_Outcome_OrigTrib if origin=="DCT" // An `if` statement is used to limit the tabulation data to a specific subset. Note that origin is a string variable so the contents must be in quotations.

tab PSM_ProceduralPosture if PSM_Outcome_OrigTrib==1 // Because PSM_Outcome_OrigTrib was recoded as a numeric variable, use the relevant value. label list [labelname] will provide the values and their labels. 

table PSM_ProceduralPosture PSM_Outcome_OrigTrib if origin=="DCT" // You can use `table` instead of `tab`' if category names are really long and are getting cut off with `tab`. 

asdoc tab  PSM_ProceduralPosture if PSM_Outcome_OrigTrib==1, save(tables2.doc) title(\i) replace // This will output the table as a Word document. Note that we currently have some nonstandard characters in the labels. We will want to clean those up. 

asdoc tab  PSM_ProceduralPosture PSM_Outcome_OrigTrib if origin=="DCT", save(tables2.doc) title(\i) append // This will add this table to the Word document (note the use of append as opposed to replace).
